package com.dkm.ec.sale.persistence.dao.impl;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.dkm.base.db.mybatis.dao.MyBatisQueryDaoImpl;
import com.dkm.ec.sale.persistence.dao.SaleSkuGroupQueryDao;
import com.dkm.ec.sale.persistence.entity.SaleSkuGroupPo;

/**
 * 对象功能:销售产品SKU自定义组 QueryDao接口的实现
 * 开发公司:SKG.COM
 * 开发人员:HJD
 * 创建时间:2015-07-08 17:38:34
 */
@Repository
public class SaleSkuGroupQueryDaoImpl extends MyBatisQueryDaoImpl<String, SaleSkuGroupPo> implements SaleSkuGroupQueryDao{

    @Override
    public String getNamespace() {
        return SaleSkuGroupPo.class.getName();
    }

	@Override
	public List<SaleSkuGroupPo> findGroups(Map<String, Object> params) {
		return findByKey("findGroups", params);
	}

	@Override
	public List<SaleSkuGroupPo> findGroupsByGroupKey(Map<String, Object> params) {
		return findByKey("findGroupsByGroupKey", params);
	}
	
	@Override
	public  SaleSkuGroupPo findGroupByGroupKey(Map<String, Object> params) {
		List<SaleSkuGroupPo> saleSkuGroupList = findByKey("findGroupsByGroupKey", params);
		SaleSkuGroupPo saleSkuGroupPo = new SaleSkuGroupPo();
		StringBuilder targetConfigName = new StringBuilder();
		StringBuilder targetConfig =new StringBuilder();
//		List<SaleSkuPo> saleSkuPos = new ArrayList<SaleSkuPo>();
		for(SaleSkuGroupPo po:saleSkuGroupList){
//			saleSkuGroupPo.setGroup(po.getGroup());
			saleSkuGroupPo.setGroup((String) params.get("group"));
			saleSkuGroupPo.setGroupName(po.getGroupName());
			targetConfigName.append(po.getSkuName()).append(",");
			targetConfig.append(po.getSkuId()).append(",");
			/*SaleSkuPo saleSkuPo = new SaleSkuPo();
			saleSkuPo.setId(po.getSkuId());
			saleSkuPo.setSkuName(po.getSkuName());
			saleSkuPos.add(saleSkuPo);*/
		}
		saleSkuGroupPo.setTargetConfig(targetConfig.toString().substring(0, targetConfig.length()-1));
		saleSkuGroupPo.setTargetConfigName(targetConfigName.toString().substring(0,targetConfigName.length()-1));
		return saleSkuGroupPo;
	}

	@Override
	public Integer countGroup() {
		String statement=getNamespace() + ".countGroup";
		Object object = sqlSessionTemplate.selectOne(statement);
		return (Integer)object;
	}

	@Override
	public List<SaleSkuGroupPo> findAppointOptLists() {
		 	return findByKey("findGroupsByAppointDef", null);
	}
	
}
